home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / gcoope10.zip / POINTER.C < prev    next >
Text File  |  1994-07-22  |  2KB  |  94 lines

  1. /*
  2.  
  3.     Pointer object class definition for GCOOPE 1.0
  4.  
  5.     Compatible with experimental strong type checking.
  6.  
  7.     Released as Public Domain    July, 1994.
  8.  
  9. */
  10.  
  11. #define CLASS Pointer
  12.  
  13. #include "gcoope10.h"
  14. #include <stdio.h>
  15.  
  16. object CLASS;
  17.  
  18. extern object String;
  19. extern object LongInt;
  20.  
  21. USEGEN(changeVal);
  22. USEGEN(valueOf);
  23. USEGEN(asString);
  24. USEGEN(asLongInt);
  25. USEGEN(asPointer);
  26.  
  27. cmethod object m4New(object instance, void * initVal)
  28. {
  29. void ** ivptr;
  30.  
  31. if(NULL==(ivptr=makeInst(&instance))) return 0;
  32. *ivptr=initVal;
  33.  
  34. return instance;
  35. }
  36.  
  37.  
  38. imethod object m4changeVal(object instance, void * newVal)
  39. {
  40. void ** ivptr;
  41.  
  42. if(NULL==(ivptr=getIVptr(instance))) return FUNCFAIL;
  43. *ivptr=newVal;
  44.  
  45. return FUNCOKAY;
  46. }
  47.  
  48.  
  49. imethod void * m4valueOf(object instance)
  50. {
  51. return *((void **) getIVptr(instance));
  52. }
  53.  
  54.  
  55. imethod object m4asString(object instance)
  56. {
  57. char strBuf[16];
  58. void * a;
  59.  
  60. a=*((void **) getIVptr(instance));
  61. sprintf(strBuf,"%p", a);
  62. return g(New)(String,strBuf);
  63. }
  64.  
  65. imethod object m4asLongInt(object instance)
  66. {
  67. void * a;
  68.  
  69. a=*((void **) getIVptr(instance));
  70.  
  71. return g(New)(LongInt,(long) a);
  72. }
  73.  
  74.  
  75.  
  76. CLASS_INSTALL
  77. {
  78. stat x=FUNCFAIL;
  79.  
  80. if(END==(CLASS=g(New)(Class, 0, sizeof(void *), END)))
  81.     goto end;
  82. if(addGMthd(CLASS, New, (method) m4New)) goto end;
  83. if(addGMthd(CLASS, GEN(changeVal), (method) m4changeVal)) goto end;
  84. if(addGMthd(CLASS, GEN(valueOf), (method) m4valueOf)) goto end;
  85. if(addGMthd(CLASS, GEN(asString), (method) m4asString)) goto end;
  86. if(addGMthd(CLASS, GEN(asLongInt), (method) m4asLongInt)) goto end;
  87. if(addGMthd(CLASS, GEN(asPointer), bounceBack)) goto end;
  88. x=FUNCOKAY;
  89.  
  90. end:
  91. return x;
  92. }
  93.  
  94.